home *** CD-ROM | disk | FTP | other *** search
- { Popup.pas -- Create a floating popup menu }
-
- program Popup;
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- cm_Item1 = 100; { Popup menu command IDs }
- cm_Item2 = 101;
- cm_Quit = 102;
-
- type
-
- PopupApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PPopupWindow = ^PopupWindow;
- PopupWindow = object(TWindow)
- procedure CMItem1(var Msg: TMessage);
- virtual cm_First + cm_Item1;
- procedure CMItem2(var Msg: TMessage);
- virtual cm_First + cm_Item2;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- procedure WMRButtonDown(var Msg: TMessage);
- virtual wm_First + wm_RButtonDown;
- end;
-
-
- { PopupApplication }
-
- {- Initialize PopupApplication object's window }
- procedure PopupApplication.InitMainWindow;
- begin
- MainWindow := New(PPopupWindow,
- Init(nil, 'Click right mouse button for menu'))
- end;
-
-
- { PopupWindow commands }
-
- procedure PopupWindow.CMItem1(var Msg: TMessage);
- begin
- MessageBox(HWindow, 'Item #1', 'Message', mb_Ok)
- end;
-
- procedure PopupWindow.CMItem2(var Msg: TMessage);
- begin
- MessageBox(HWindow, 'Item #2', 'Message', mb_Ok)
- end;
-
- procedure PopupWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- {- Create, display, use, and destroy the floating menu }
- procedure PopupWindow.WMRButtonDown(var Msg: TMessage);
- var
- P: TPoint; { Sets menu location at mouse pointer }
- PopupMenuH: HMenu; { Popup menu handle }
- begin
- PopupMenuH := CreatePopupMenu;
- AppendMenu(PopupMenuH, mf_Enabled, cm_Item1, 'Item 1');
- AppendMenu(PopupMenuH, mf_Enabled, cm_Item2, 'Item 2');
- AppendMenu(PopupMenuH, mf_Enabled, cm_Quit, 'E&xit');
- P.X := Msg.LParamLo;
- P.Y := Msg.LParamHi;
- ClientToScreen(HWindow, P);
- TrackPopupMenu(PopupMenuH, 0, P.X, P.Y, 0, HWindow, nil);
- DestroyMenu(PopupMenuH)
- end;
-
- var
-
- PopupApp: PopupApplication;
-
- begin
- PopupApp.Init('PopupApp');
- PopupApp.Run;
- PopupApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 2/20/1991
- ---------------------------------------------------------------}
-